/**
 * FileName: CheckInHandler
 * Author:   mjh
 * Date:     2019/8/1 12:14
 * Description: CheckIn表现层
 * History:
 * <author>          <time>          <version>          <desc>
 * mjh         修改时间           版本号              描述
 */
package com.woniuxy.main.handler;

import com.woniuxy.main.pojo.CheckIn;
import com.woniuxy.main.service.CheckInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br>
 * 〈CheckIn表现层〉
 *
 * @author mjh
 * @create 2019/8/1
 * @since 1.0.0
 */

@Controller
@RequestMapping("/checkIn")
public class CheckInHandler {

    @Autowired
    private CheckInService checkInService;

    @RequestMapping("/findAll")
    @ResponseBody
    public List<CheckIn> findAll() {
        System.out.println(checkInService.findAll());
        return checkInService.findAll();
    }

    @RequestMapping("/findUserByother")
    @ResponseBody
    public List<CheckIn> findUserByother(CheckIn checkIn) {

        return checkInService.findByOther(checkIn);
    }

    @RequestMapping("/findUserBylike")
    @ResponseBody
    public List<CheckIn> findUserBylike(CheckIn CheckIn) {
        CheckIn CheckIn1 = new CheckIn();
        //CheckIn1.setScard("%902%");
        //CheckIn1.setCname("%香蕉%");
        CheckIn1.setCphone("%43%");
        return checkInService.findByLike(CheckIn1);
    }

    /**
     * 根据房间号 查询该房间内入住人信息
     *
     * @return 入住人 Map集合
     * @throws Exception 全部
     */
    @RequestMapping("/findByRoomId")
    public @ResponseBody
    Map findByRoomId(@RequestParam(name = "room_id") Integer room_id) throws Exception {

        CheckIn checkIn = new CheckIn();
        checkIn.setRoom_id(room_id);
        List<CheckIn> checkInList = checkInService.findByOther(checkIn);
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("code", 0);
        result.put("msg", "");
        result.put("count", checkInList.size());
        result.put("data", checkInList);
        return result;
    }

    /**
     * 添加:入住用户信息
     *
     * @param checkIn
     * @return
     * @throws Exception
     */
    @RequestMapping("/add")
    public @ResponseBody
    String addCheckIn(CheckIn checkIn) throws Exception {
        boolean flag = checkInService.addCheckIn(checkIn);
        return "" + flag;
    }


}